﻿using AntdUI;

namespace DataAcquisition.Main.Base
{
    public partial class DABaseForm : Window
    {
        #region 属性

        /// <summary>是否全屏
        /// 
        /// </summary>
        public bool FullScreen { get; set; }

        #endregion

        #region 自定义方法

        /// <summary>Success消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Success(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.success(this, msg, Font, 1);
            }));
        }

        /// <summary>Info消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Info(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.info(this, msg, Font, 1);
            }));
        }

        /// <summary>Warn消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Warn(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.warn(this, msg, Font, 1);
            }));
        }

        /// <summary>Error消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Error(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.error(this, msg, Font, 1);
            }));
        }

        /// <summary>
        /// loading
        /// </summary>
        /// <param name="control">加载到哪个控制器</param>
        /// <param name="text">提示文字</param>
        /// <param name="action">耗时操作</param>
        /// <param name="config">loading样式</param>
        /// <param name="end">结束回调</param>
        public void DCSpin(Control control, string text, Action<AntdUI.Spin.Config> action, AntdUI.Spin.Config? config = null, Action? end = null)
        {
            text = text == null ? "正在执行..." : text;
            if (config == null)
            {
                config = new AntdUI.Spin.Config()
                {
                    Back = Color.FromArgb(220, 147, 181, 207),
                    Color = Style.Db.Primary,//转圈颜色
                    Radius = 6,
                    Fore = Color.Black,//字体颜色
                    Font = new Font("Microsoft YaHei UI", 14f),//字体可以控制进度圈的大小
                    Text = text
                };
            }
            AntdUI.Spin.open(this, config, action, end);
        }

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="autoClose">自动关闭(s) 0-不自动关闭</param>
        public void ErrorNotification(string message, int autoClose = 3)
        {
            AntdUI.Notification.error(this, "友情提示", message, autoClose: autoClose, align: TAlignFrom.TR);
        }

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="autoClose">自动关闭(s) 0-不自动关闭</param>
        public void WarnNotification(string message, int autoClose = 3)
        {
            AntdUI.Notification.warn(this, "友情提示", message, autoClose: autoClose, align: TAlignFrom.TR);
        }

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="autoClose">自动关闭(s) 0-不自动关闭</param>
        public void InfoNotification(string message, int autoClose = 3)
        {
            AntdUI.Notification.info(this, "友情提示", message, autoClose: autoClose, align: TAlignFrom.TR);
        }

        /// <summary>
        /// 通知
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <param name="autoClose">自动关闭(s) 0-不自动关闭</param>
        public void SuccessNotification(string message, int autoClose = 0)
        {
            AntdUI.Notification.success(this, "友情提示", message, autoClose: autoClose, align: TAlignFrom.TR);
        }

        /// <summary>
        /// 绑定属性
        /// </summary>
        /// <param name="control"></param>
        /// <param name="controlProperty"></param>
        /// <param name="modelProperty"></param>
        public void Bindings(Control control, string controlProperty, string modelProperty, object viewModel)
        {
            control.DataBindings.Add(new System.Windows.Forms.Binding(controlProperty, viewModel, modelProperty, true, DataSourceUpdateMode.OnPropertyChanged));
        }

        #endregion

        #region 系统事件
        public DABaseForm()
        {
            InitializeComponent();
        }

        private void DABaseForm_Load(object sender, EventArgs e)
        {
            if (FullScreen)
            {
                if (Screen.PrimaryScreen is not null)
                {
                    Screen primaryScreen = Screen.PrimaryScreen;
                    ScreenRectangle = new Rectangle(0, 0, primaryScreen.WorkingArea.Size.Width, primaryScreen.WorkingArea.Height);
                    MaximizedBounds = primaryScreen.WorkingArea;
                    MinimumSize = primaryScreen.WorkingArea.Size;
                }
            }
        }
        #endregion
    }
}
